#pragma once

#include <string>

#include "astar.hh"
#include "builder.h"
#include "contest_db.h"
#include "def_service.h"
#include "flute3/flute.h"
#include "gridmap/gridmap.hh"
#include "lef_service.h"

namespace ieda_contest {

class MakeRoute
{
 public:
  MakeRoute() = default;
  MakeRoute(ContestDataManager* data_manager);
  ~MakeRoute() = default;

  void doRoute(ContestNet* contest_net);
  
  void updateGridMapInfo(std::set<ContestCoord> gcell_lists) {
    for (auto gcell : gcell_lists) {
      _grid_map.set_full_resource(gcell.get_x(), gcell.get_y(), gcell.get_layer_idx());
    }
  }

  void updateGridMapInfo(std::map<ContestCoord, int> gcell_used) {
    for (auto [gcell, used] : gcell_used) {
      _grid_map.set_demand_info(gcell.get_x(), gcell.get_y(), gcell.get_layer_idx(), used);

    }
  }
 private:
  void updateGuide(ContestNet* contest_net);
  std::vector<ContestGuide> getGuide(ContestSegment& routing_segment);
  std::vector<ContestCoord> makeKeyCoordList(ContestNet* contest_net);
  std::vector<ContestSegment> getRoutingSegmentList(ContestSegment& topo, ContestNet* contest_net);
  ContestDataManager* _data_manager = nullptr;
  void createMap();
  std::vector<ContestSegment> getTopoListByFlute(std::vector<ContestCoord>& coord_list);

  ieda_contest::gridmap::Map<astar::Node<3>> _grid_map;
  ieda_contest::astar::PathFinder<3> _pathfinder;
};

}  // namespace ieda_contest